<!DOCTYPE html>
<html>
<head>
    <title>找攻略</title>
    <meta charset="utf-8"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <link rel="stylesheet" href="/js/bootstrap/css/bootstrap.min.css">
    <link rel="stylesheet" href="/css/font/css/font-awesome.min.css">
    <link rel="stylesheet" href="/css/reset.css"/>
    <link rel="stylesheet" href="/css/strategy.css"/>
    <link rel="stylesheet" href="/js/plugins/dialog/dialog.css">
    <script src="/js/jquery/jquery.min.js"></script>
    <script src="/js/bootstrap/js/bootstrap.min.js"></script>
    <script src="/js/plugins/dialog/dialog.min.js"></script>
    <script src="/js/plugins/jrender/jrender.js"></script>
    <script src="/js/common.js"></script>

    <script>
        //创建一个选项卡的方法
        function createTab(index, obj) {
            /*<li class="nav-item" data-index="xx">
            <a data-tid="xx" class="nav-link" data-toggle="pill" href="#pills-xx">oo</a>
                    </li>*/
            var a = $("<a class='nav-link' data-toggle='pill'></a>").attr("data-tid", obj.id)
                .attr("href", "#pills-" + obj.id).html(obj.name);
            return $("<li class='nav-item'></li>").attr("data-index", index).append(a);
        }

        $(function () {
            //显示推荐的攻略游记
            $.get("/travels/commend", {type: 3}, function (data) {
                $(".commend").renderValues(data[0], {
                    handler: function (ele, val) {
                        ele.href = "travelContent.html?id=" + val;
                    }
                });
            })
            //显示推荐的大攻略
            $.get("/strategys/commends", function (data) {
                $(".strategyCommend").renderValues({list: data}, {
                    hand: function (ele, val) {
                        ele.href = "strategyCatalogs.html?strategyId=" + val;
                    }
                })
            })

            var tabs = [];
            var tab;
            //获取推荐的热门区域,并创建选项卡
            $.get("/regions/hots", {state: 1}, function (data) {
                $.each(data, function (index, ele) {
                    createTab(index, ele).appendTo("#pills-tab");
                    $.get("/regions/" + ele.id + "/strategies", {pageSize: 2}, function (data) {
                        $(data).appendTo("#pills-tabContent");
                        //保存选择卡信息
                        tabs[index] = {currentPage: 1, pages: $(data).data("pages"), placeId: ele.id}
                    }, "html")
                })
                $("#pills-tab li[data-index]").click(function () {
                    var index = $(this).data("index");
                    tab = tabs[index];
                    console.log(tab);
                })
            })

            $(window).scroll(function () {
                if (isFull()) {
                    if (tab && tab.currentPage < tab.pages) {
                        $.get("/regions/" + tab.placeId + "/strategies", {currentPage: ++tab.currentPage, pageSize: 2},
                            function (data) {
                                /*把进行分页查询返回来的数据添加到对应的区域标签中,由于同时存在多个区域,
                                    所以先用ID选择器选到指定的区域*/
                                $(data).appendTo("#pills-" + tab.placeId + " .classify");
                            }, "html")
                    } else {
                        $(document).dialog({
                            type: "notice",
                            infoText: "到底部了",
                            autoClose: 2500,
                            position: "bottom"  // center: 居中; bottom: 底部
                        });
                    }

                }

            })

        });
    </script>

</head>

<body>
<div class="search-head">
    <div class="row nav-search">
        <div class="col-2">
            <a href="index.html">
                <span><i class="fa fa-chevron-left fa-2x"></i></span>
            </a>
        </div>
        <div class="col-10">
            <div class="input-group-sm search">
                <input class="form-control searchBtn" placeholder="找攻略">
            </div>
        </div>
    </div>
</div>

<ul class="nav nav-pills nav-justified border border-left-0 border-top-0 border-right-0" id="pills-tab" role="tablist">
    <li class="nav-item">
        <a class="nav-link active show" data-toggle="pill" href="#pills-top">
            <span style="font-weight: bold;">推荐</span>
        </a>
    </li>
</ul>

<div class="tab-content" id="pills-tabContent">
    <div class="tab-pane fade active show" id="pills-top">
        <div class="container commend">
            <a render-fun="handler" render-key="travelId">
                <img render-src="coverUrl">
                <p render-html="title"></p>
            </a>
        </div>
        <hr>
        <div class="container strategyCommend">
            <h6>当季推荐</h6>
            <div class="row hot" render-loop="list">
                <div class="col-4">
                    <a render-fun="hand" render-key="list.id" href="strategyCatalogs.html">
                        <img render-src="list.coverUrl">
                        <p render-html="list.title"></p>
                    </a>
                </div>
            </div>
        </div>
    </div>

</div>

</body>
</html>